<?php
class Default_Model_TableColumn_Users {
	const DATE_FORMAT_FULL_EN = 'Y-m-d H:i:s';
	const DATE_FORMAT_FULL_VN = 'd-m-Y H:i:s';
	const DATE_FORMAT_SHORT_VN = 'd-m-Y';

	protected $id;
	protected $email;
	protected $password;
	protected $username;
	protected $tai_khoan_chinh;
	protected $tai_khoan_khuyen_mai;
	protected $gioi_tinh;
	protected $ho_ten;
	protected $ngay_sinh;
	protected $dia_chi;
	protected $hinh_anh;
	protected $dien_thoai;
	protected $dang_nhap_cuoi;
	protected $kich_hoat;
	protected $thanh_pho;
	protected $ngay_tao;
	protected $ngay_cap_nhat;
	protected $nguoi_cap_nhat;
	protected $ma_kich_hoat;
	protected $ngay_kich_hoat;
	protected $diem;

	public function __construct(array $options = null) {
		if (is_array($options)) {
			$this->setOptions($options);
		}
	}
	public function __set($name, $value) {
		$method = 'set' . $name;
		if (('mapper' == $name) || !method_exists($this, $method)) {
			throw new Exception('Invalid content property');
		}
		$this->$method($value);
	}
	public function __get($name) {
		$method = 'get' . $name;
		if (('mapper' == $name) || !method_exists($this, $method)) {
			throw new Exception('Invalid content property');
		}
		return $this->$method();
	}
	public function setOptions(array $options) {
		$methods = get_class_methods($this);
		foreach ($options as $key => $value) {
			$method = 'set' . ucfirst($key);
			if (in_array($method, $methods)) {
				$this->$method($value);
			}
		}
		return $this;
	}
	//Id
	public function getId() {
		return $this->id;
	}
	public function setId($id) {
		$this->id = $id;
	}
	//Email
	public function getEmail() {
		return $this->email;
	}
	public function setEmail($email) {
		$this->email = $email;
	}
	//Pass
	public function setPassword($password) {
		$this->password = $password;
	}
	public function getPassword() {
		return $this->password;
	}
	//Username
	public function getUsername() {
		return $this->username;
	}
	public function setUsername($username) {
		$this->username = $username;
	}
	// tai_khoan_chinh
	public function getTai_khoan_chinh(){
		return $this->tai_khoan_chinh;
	}
	public function setTai_khoan_chinh($value){
		$this->tai_khoan_chinh=$value;
	}
	// tai_khoan_khuyen_mai
	public function getTai_khoan_khuyen_mai(){
		return $this->tai_khoan_khuyen_mai;
	}
	public function setTai_khoan_khuyen_mai($value){
		$this->tai_khoan_khuyen_mai=$value;
	}
	// gioi_tinh
	public function getGioi_tinh(){
		return $this->gioi_tinh;
	}
	public function setGioi_tinh($value){
		switch ($value) {
			case 'female':
				$this->gioi_tinh = FALSE;
			case 'male':
				$this->gioi_tinh = TRUE;
			default:
				$this->gioi_tinh = $value;
		}
	}

	// ho_ten
	public function getHo_ten() {
		return $this->ho_ten;
	}

	public function setHo_ten($value) {
		$this->ho_ten = $value;
	}

	// ngay_sinh
	public function getNgay_sinh($format = self::DATE_FORMAT_FULL_EN) {
		if ($this->ngay_sinh) {
			return date($format, strtotime($this->ngay_sinh));
		}
		return null;
	}

	public function setNgay_sinh($value) {
		if ($value!=null&&$value!='') {
			$this->ngay_sinh = date(self::DATE_FORMAT_FULL_EN, strtotime($value));
		}
	}

	// dia_chi
	public function getDia_chi() {
		return $this->dia_chi;
	}

	public function setDia_chi($value) {
		$this->dia_chi = $value;
	}

	// hinh_anh
	public function getHinh_anh() {
		return $this->hinh_anh;
	}

	public function setHinh_anh($value) {
		$this->hinh_anh = $value;
	}

	// dien_thoai
	public function getDien_thoai() {
		return $this->dien_thoai;
	}

	public function setDien_thoai($value) {
		$this->dien_thoai = $value;
	}

	// dang_nhap_cuoi
	public function getDang_nhap_cuoi($format = self::DATE_FORMAT_FULL_EN) {
		if ($this->dang_nhap_cuoi) {
			return date($format,strtotime($this->dang_nhap_cuoi));
		}
		return null;
	}

	public function setDang_nhap_cuoi($value) {
		if ($value!=null&&$value!='') {
			$this->dang_nhap_cuoi = date($format = self::DATE_FORMAT_FULL_EN, strtotime($value));
		}
	}

	// kich_hoat
	public function getKich_hoat() {
		return $this->kich_hoat;
	}

	public function setKich_hoat($value) {
		$this->kich_hoat= $value;
	}

	// thanh_pho
	public function getThanh_pho() {
		return $this->thanh_pho;
	}

	public function setThanh_pho($value) {
		$this->thanh_pho = $value;
	}

	// ngay_tao
	public function getNgay_tao($format=self::DATE_FORMAT_FULL_EN) {
		if($this->ngay_tao)
			return date($format, strtotime($this->ngay_tao));
		return null;
	}

	public function setNgay_tao($value) {
		if ($value!=null&&$value!='') {
			$this->ngay_tao = date(self::DATE_FORMAT_FULL_EN, strtotime($value));
		}
	}

	// ngay_cap_nhat
	public function getNgay_cap_nhat($format = self::DATE_FORMAT_FULL_EN) {
		if($this->ngay_cap_nhat){
			return date($format, strtotime($this->ngay_cap_nhat));
		}
		return null;
	}

	public function setNgay_cap_nhat($value) {
		if ($value!=null&&$value!='') {
			$this->ngay_cap_nhat = date(self::DATE_FORMAT_FULL_EN, strtotime($value));
		}
	}

	// nguoi_cap_nhat
	public function getNguoi_cap_nhat() {
		return $this->nguoi_cap_nhat;
	}

	public function setNguoi_cap_nhat($value) {
		$this->nguoi_cap_nhat = $value;
	}

	//thanh pho
	public function getThanhPhoObj() {
		$thanhpho = new Admin_Model_ThanhPhoMapper();
		if($this->getThanh_pho() != null){
			foreach ($thanhpho->fetchAll('id = '. $this->getThanh_pho(), 'view') as $thanhphoobj)
			return $thanhphoobj;
		}
	}
	// ma_kich_hoat
	public function getMa_kich_hoat() {
		return $this->ma_kich_hoat;
	}
	public function setMa_kich_hoat($value) {
		$this->ma_kich_hoat = $value;
	}
	// ngay_kich_hoat
	public function getNgay_kich_hoat($format = self::DATE_FORMAT_FULL_EN) {
		if($this->ngay_kich_hoat){
			return date($format, strtotime($this->ngay_kich_hoat));
		}
		return null;
	}

	public function setNgay_kich_hoat($value) {
		if ($value!=null&&$value!='') {
			$this->ngay_kich_hoat = date(self::DATE_FORMAT_FULL_EN, strtotime($value));
		}
	}
	// to array
	public function toArray() {
		$data = array(
			'id'		    		=> $this->id,
			'email'    				=> $this->email,
			'username'     			=> $this->username,
			'password'     			=> $this->password,
			'tai_khoan_chinh' 	    => $this->tai_khoan_chinh,
			'tai_khoan_khuyen_mai'	=> $this->tai_khoan_khuyen_mai,
			'gioi_tinh'	    		=> $this->gioi_tinh,
			'ho_ten'		    	=> $this->ho_ten,
			'ngay_sinh'				=> $this->getNgay_sinh('d-m-Y'),
			'dia_chi'	    		=> $this->dia_chi,
			'hinh_anh'		    	=> $this->hinh_anh,
			'dien_thoai'			=> $this->dien_thoai,
			'dang_nhap_cuoi'	    => $this->dang_nhap_cuoi,
			'kich_hoat'		    	=> $this->kich_hoat,
			'thanh_pho'				=> $this->thanh_pho,
			'ngay_tao'				=> $this->ngay_tao,
			'ngay_cap_nhat'		    => $this->ngay_cap_nhat,
			'nguoi_cap_nhat'		=> $this->nguoi_cap_nhat,
			'ma_kich_hoat'		    => $this->ma_kich_hoat,
			'ngay_kich_hoat'		=> $this->ngay_kich_hoat,
		);
		$item = array();
		foreach ($data as $key =>$value) {
			if ($value != '' && $value != null) {
				$item[$key] = $value;
			}
		}
		return $item;
	}
	
	public function getDiem() {
		return $this->diem;
	}
	
	public function setDiem($value) {
		$this->diem = $value;
	}
}